<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%--3、注册功能：
		点击注册后，将收集到的信息存入数据库中
		(1)、获取注册界面传递过来的数据
		(2)、连接数据库
		(3)、将信息存入数据库 --%>
		<% //(1)、获取注册界面传递过来的数据
		String yhm = request.getParameter("yonghuming");
		String mm = request.getParameter("mima");
		String sjh = request.getParameter("shoujihao");
	
		%>
		<%
		//(2)、连接数据库
		String dbName = "studb";
		String dbUser = "root";
		String dbPwd = "123456";
		String url = "jdbc:mysql://localhost/"+dbName+"?user="+dbUser+"&password="+dbPwd;
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection(url);
		%>
		<%
		//(3)、将信息存入数据库
			String sql = "insert into user values('"+yhm+"','"+mm+"','"+sjh+"')";
			Statement s = conn.createStatement();
			int result  = s.executeUpdate(sql);
			if(result > 0){
			out.println("注册成功");
			}else{
			out.println("注册失败");
			}
		 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>注册功能</title>



  </head>
  <a href="shiyan_denglu.jsp">，去登录</a>
  <body>
    
  </body>
</html>
